<?php
/**
 * Klasa odpowiadająca za obsługę sesji
 * 
 * @author Marcin
 */
class Session {
	private $SessId;
	private $remoteAddr;
	private $data = array();
	private $dbc;
	
	public function __construct($dbc, $sessId = NULL, $remoteAddr = NULL) {
		$this->dbc = $dbc;
		if($sessId && $remoteAddr) {
			$this->SessId = $sessId;
			$this->remoteAddr = $remoteAddr;
			
			$r = $this->dbc->prepare('SELECT * FROM sessions WHERE sessid = :sessid AND remoteAddr = :remoteaddr')
							.execute(array(':sessid'=>$this->SessId, ':remoteaddr'=>$this->remoteAddr))
							.fetch(PDO::FETCH_ASSOC);
							
			if($r == NULL) {
				return NULL;
			}
			$data = json_decode($r['data']);
		}
	}
}
